package Week.w153;

import org.junit.Test;

import java.util.*;
public class Solution04 {

    public int distanceBetweenBusStops(int[] distance, int start, int destination) {
        if(start==destination){
            return 0;
        }
        int result1=0;
        int result2=0;
        int indexSmall=Math.min(start,destination);
        int indexMax=Math.max(start,destination);

        for(int i=indexSmall;i<indexMax;i++){
            result1+=distance[i];
        }
        for(int j=indexMax;;j++){
            int index=j%distance.length;
            if(index==indexSmall){
                break;
            }
            result2+=distance[index];
        }
        return Math.min(result1,result2);
    }


    public String dayOfTheWeek(int day, int month, int year) {
        String[] result=new String[]{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
        int indexStart=5;

        int curIndex=(year-1971)+indexStart;
        if(year>=1972){
            int num=0;
            if(year%4!=0){
                num=(year-1972)/4+1;
            }else {
                num=(year-1972)/4;
            }
            curIndex+=num;
        }
        curIndex=curIndex%7;

        int[] mon=new int[]{31,28,31,30,31,30,31,31,30,31,30,31};

        for(int i=0;i<month-1;i++){
            curIndex+=mon[i];
        }
        if(year%4==0&&month>2){
            curIndex++;
        }
        curIndex=curIndex%7;
        curIndex=day+curIndex-1;
        return result[curIndex%7];
    }

/*
    public int maximumSum(int[] arr) {

    }
*/


    @Test
    public void test1(){
        System.out.println(dayOfTheWeek(29,2,2016));
  /*      System.out.println(dayOfTheWeek(6,3,1995));
        System.out.println(dayOfTheWeek(6,3,1995));
        System.out.println(dayOfTheWeek(6,3,1995));*/
    }
}
